

import { Controller } from 'egg';

export default class HomeController extends Controller {
  public async index() {
    const { ctx } = this;
    ctx.body = await ctx.service.test.sayHi('egg');
  }

  // music/url  22854061,219084
  public async url() {
    const { id, br } = this.ctx.queries;
    const data = { ids: id, br: br || 320000, csrf_token: "" };

    console.log('id is ', id)

    const url = `/weapi/song/enhance/player/url`;
    let result = await this.service.mequest.createWebAPIRequest(url, 'POST', data)
    const { body, cookie } = result;

    cookie && this.service.mequest.parseCookie(cookie).forEach(ck => {

      this.ctx.cookies.set(ck.cookie.name, ck.cookie.value, ck.options)
    })
    this.ctx.body = body;
  }

  // music/check
  public async check() {
    const { id, br } = this.ctx.queries;
    const data = { ids: id, br: br || 320000, csrf_token: "" };

    console.log('id is ', id)

    const url = `/weapi/song/enhance/player/url`;
    let result = await this.service.mequest.createWebAPIRequest(url, 'POST', data)
    const { body } = result;

    this.ctx.body = body;
  }
  //  /music/lyric
  public async lyric() {
    const id = this.ctx.query.id;
    const url = `/weapi/song/lyric?os=osx&id=${id}&lv=-1&kv=-1&tv=-1`;
    let result = await this.service.mequest.createWebAPIRequest(url, 'POST', {})
    const { body } = result;

    this.ctx.body = body;
  }
  // music/detail?id=450226742
  public async detail() {
    const id = this.ctx.query.id;
    const data = {
      c: JSON.stringify([{ id: id }]),
      ids: `[${id}]`
    }
    const url = `/weapi/v3/song/detail`;
    let result = await this.service.mequest.createWebAPIRequest(url, 'POST', data)
    const { body } = result;
    this.ctx.body = body;
  }
  

}